﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;
using DAL.Entities;

namespace DAL.Entities_DAL
{
    public class NCC_DAL: BaseDAL
    {

        public DataTable Select_max()
        {
            var sql = @"SELECT max(MA_NCC) as id FROM NHA_CC";
            return ExecuteQuery(sql);
        }

        public string Select_count()
        {
            string sql = @"SELECT count(MA_NCC) as id FROM NHA_CC";
            var tb = ExecuteQuery(sql);
            return tb.Rows.Count > 0 ? tb.Rows[0]["id"] + "" : "0";
        }

        public DataTable Select()
        {
            var sql = @"SELECT * FROM NHA_CC";
            return ExecuteQuery(sql);
        }

        public bool Delete(string id)
        {
            string sql = @"DELETE FROM NHA_CC WHERE MA_NCC = '{0}'";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (NHA_CC)obj;
            string sql = @"set dateformat dmy;INSERT INTO NHA_CC(MA_NCC, TEN_NCC, D_CHI) VALUES('{0}',N'{1}',N'{2}')";
            sql = string.Format(sql, o.MA_NCC, o.TEN_NCC, o.D_CHI);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (NHA_CC)obj;
            string sql = @"set dateformat dmy;UPDATE NHA_CC SET TEN_NCC=N'{1}', D_CHI = N'{2}' where MA_NCC='{0}'";
            sql = string.Format(sql, o.MA_NCC, o.TEN_NCC, o.D_CHI);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }
    }
}
